<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    <title>Document</title>
</head>
<body>
<form enctype="multipart/form-data" method="post">
    <input type="text" name="userID" id="userID" value="YK91812053"> <br>
    <input type="text" name="nickname" id="nickname" value="hello"> <br>
    <!-- <input type="text" name="sex" id="sex" value="1"> <br>
    <p>上传avatar文件<input type="file" id="avatar" name="avatar"/></p>
    <p>上传bkImg文件<input type="file" id="bkImg" name="bkImg"/></p> -->
    <button id="import" onclick="submitForm1()">导入</button>
</form>
<script type="text/javascript">
        // 普通文件
        function submitForm1() {
            $.ajax({
                type: 'get',
                url: "http://localhost:8001/",
                // url: "http://127.0.0.1:8001/api/user/update",
                // data: 'userID=YK91812053&nickname=hello&sex=1',
                async: false,
                dataType: "json" ,
                success: function (ret) {
                    alert(ret);
                }
            });
        };

        //  文件和普通数据，  也就是使用文件流的形式
        function submitForm2(){
            var formData = new FormData();//必须是new FormData后台才能接收到
            formData.append("userID", $("#userID").val());
            formData.append("nickname", $("#nickname").val());
            formData.append("sex", $("#sex").val());
            formData.append("avatar", $("#avatar")[0].files[0]);
            formData.append("bkImg", $("#bkImg")[0].files[0]);
            $.ajax({
                type: 'put',
                url: "http://127.0.0.1:9999/api/user/update",
                data: formData,
                contentType: false,//必须false才会自动加上正确的Content-Type
                processData: false,//必须false才会避开jQuery对 formdata 的默认处理，XMLHttpRequest会对 formdata 进行正确的处理
                success: function (res) {
                    console.log(res);
                }
            });
        }

</script>
</body>
</html>